<?php
/**
 * 信息中心控制器
 */
namespace Home\Controller;
use Think\Controller;
class InformationController extends InitController {	
	//信息中心
	public function index(){
	   	$page         = I('page',0,'intval');
		$limit        = '';
		$index        = 10;
		$page_all     = 0;
		$files        = 'id,title,createtime';
        //获取页数
		if(!empty($page)){
			$now_page = ($page + 1); 
			$page_all = $page * $index;
			$limit    = $page_all.','.$index;
		}else{
			$limit    = '0,10';
		}
        
		//更新阅读标识
		M('Infomoation')->where(array('uid'=>$this->uid,'is_read'=>0))->save(array('is_read'=>1));
		
        $list = M('Infomoation')->where(array('uid'=>$this->uid))->order('id desc')->limit($limit)->select();

		 //用于ajax分页
		 if(IS_AJAX){			
			if(!empty($list)){
				foreach($list as $k=>$v){
					$list[$k]['createtime'] = date('Y-m-d H:i:s',$v['createtime']);
				}

			}
            
			return $this->ajaxReturn(array('data'=>$list,'status'=>'1'));die;
		}
		 
		 //加载变量
		 $this->assign(array(
			'list'=>$list
	     ));
        
         $this->display('index');
	}
	
}